﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MyChannel.DownloadComponent
{
    public class BaseModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private string _key;
        public virtual string Key
        {
            get
            {
                return _key;
            }
            set
            {
                if (_key != value)
                {
                    _key = value;
                    OnPropertyChanged("Key");
                }
            }
        }

        private string _name;
        public virtual string Name
        {
            get
            {
                return _name;
            }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    OnPropertyChanged("Name");
                }
            }
        }

        public string RefModuleKey
        {
            get;
            set;
        }

        protected virtual void OnPropertyChanged(string propChanged)
        {
            if (PropertyChanged != null)
            {
                if (Deployment.Current.Dispatcher.CheckAccess())
                    PropertyChanged(this, new PropertyChangedEventArgs(propChanged));
                else
                    Deployment.Current.Dispatcher.BeginInvoke(new Action<string>
                              (OnPropertyChanged), propChanged);
            }
        }

        public BaseModel Reference
        {
            get { return this; }
        }
    }
}
